package com.ruoyi.third.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.third.domain.ThirdEvent;
import com.ruoyi.third.service.IThirdEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警事件Controller
 * 
 * @author yepanpan
 * @date 2025-02-06
 */
@RestController
@RequestMapping("/third/event")
public class ThirdEventController extends BaseController
{
    @Autowired
    private IThirdEventService thirdEventService;

    /**
     * 查询告警事件列表
     */
    @PreAuthorize("@ss.hasPermi('third:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(ThirdEvent thirdEvent)
    {
        startPage();
        List<ThirdEvent> list = thirdEventService.selectThirdEventList(thirdEvent);
        return getDataTable(list);
    }

    /**
     * 导出告警事件列表
     */
    @PreAuthorize("@ss.hasPermi('third:event:export')")
    @Log(title = "告警事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThirdEvent thirdEvent)
    {
        List<ThirdEvent> list = thirdEventService.selectThirdEventList(thirdEvent);
        ExcelUtil<ThirdEvent> util = new ExcelUtil<ThirdEvent>(ThirdEvent.class);
        util.exportExcel(response, list, "告警事件数据");
    }


    /**
     * 获取告警事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('third:event:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(thirdEventService.selectThirdEventById(id));
    }

    /**
     * 新增告警事件
     */
    @PreAuthorize("@ss.hasPermi('third:event:add')")
    @Log(title = "告警事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ThirdEvent thirdEvent)
    {
        return toAjax(thirdEventService.insertThirdEvent(thirdEvent));
    }

    /**
     * 修改告警事件
     */
    @PreAuthorize("@ss.hasPermi('third:event:edit')")
    @Log(title = "告警事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ThirdEvent thirdEvent)
    {
        return toAjax(thirdEventService.updateThirdEvent(thirdEvent));
    }

    /**
     * 删除告警事件
     */
    @PreAuthorize("@ss.hasPermi('third:event:remove')")
    @Log(title = "告警事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(thirdEventService.deleteThirdEventByIds(ids));
    }
}
